﻿#region Using
/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-11-15
Description:SoftDownload.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FineUI;
using FTchina.Logic;
using FTchina.Library;
#endregion
public partial class SoftDownloadaction_cs : BasePage
{



    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            LoadData();
            string id = RequestHelper.SafeRequest(Request["id"]);
            if (id.Length > 0)
            {
                ShowModData(id);
            }
        }

    }
    private void LoadData()
    {

        // 关闭按钮的客户端脚本：
        // 1. 首先确认窗体中表单是否被修改（如果已经被修改，则弹出是否关闭的确认对话框）
        // 2. 然后关闭本窗体，回发父窗体
        btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
        ControlBindHelper.DropDownListBind(ddlType, "SoftType", "TypeName");

    }
    private void ShowModData(string ItemID)
    {
        FTchina.Models.SoftDownload mSoftDownload = FTchina.BLL.SoftDownloadManager.GetSoftDownloadById(Convert.ToInt32(ItemID));
        if (mSoftDownload != null)
        {
            txbid.Text = mSoftDownload.Id.ToString().Trim();
            txbsoftName.Text = mSoftDownload.SoftName.ToString().Trim();
            txbsoftLink.Text = mSoftDownload.SoftLink.ToString().Trim();
            txbdate.SelectedDate = mSoftDownload.Date;
            //  picLinkUp.Text = mSoftDownload.PicLink.ToString().Trim();
            txbcount.Text = mSoftDownload.Count.ToString().Trim();
            ddlType.SelectedValue = mSoftDownload.TypeName.Trim();
        }
        else
        {
            AlertLogic.ShowResultAndRedirect("无数据！", "提示", HttpContext.Current.Request.Path.ToString(), false);
        }
    }
    protected void btnSaveContinue_Click(object sender, EventArgs e)
    {
        FTchina.Models.SoftDownload mSoftDownload = new FTchina.Models.SoftDownload();

        string fileName = picLinkUp.ShortFileName;
        fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
        fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
        string pathAndFile = Server.MapPath("~/upload/" + fileName);
        if (picLinkUp.HasFile && picLinkUp.ShortFileName.Trim().Length > 0)
        {
            picLinkUp.SaveAs(pathAndFile);
           
        }
        if (picLinkUp.ShortFileName.Trim().Length > 0)
        {
            mSoftDownload.PicLink = fileName;
        }
        // 1. 这里放置保存窗体中数据的逻辑

        mSoftDownload.Id = txbid.Text.Trim() == "" ? 0 : Convert.ToInt32(txbid.Text);

        mSoftDownload.SoftName = txbsoftName.Text.Trim();
        mSoftDownload.SoftLink = txbsoftLink.Text.Trim();
        mSoftDownload.Date = Convert.ToDateTime(txbdate.Text.Trim());
        mSoftDownload.TypeName = ddlType.SelectedValue;
        mSoftDownload.Count = Convert.ToInt32(txbcount.Text.Trim());
        AlertLogic.ShowResult(FTchina.BLL.SoftDownloadManager.AddOrUpdateSoftDownload(mSoftDownload) > 0);

        // 2. 关闭本窗体，然后回发父窗体
        PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
    }
    //protected void btnSaveRefresh_Click(object sender, EventArgs e)
    //{
    //    // 1. 这里放置保存窗体中数据的逻辑

    //    // 2. 关闭本窗体，然后刷新父窗体
    //    PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
    //}






}






